﻿using Common.Model;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;

namespace Bussiness.Interface
{
    public interface IBaseService : IDisposable  
    {
        #region IQueryable
        /// <summary>
        /// 单表查询
        /// </summary>
        /// <returns>IQueryable类型集合</returns>
        Result<IEnumerable<T>> GetTable<T>() where T : class;
        #endregion

        #region===Select===
        /// <summary>
        /// 查找全部
        /// </summary>
        /// <returns></returns>
        Result<List<T>> Select<T>() where T : class;

        /// <summary>
        /// 根据条件查找
        /// </summary>
        /// <param name="expreesions">lambda表达式数组</param>
        /// <returns></returns>
        Result<List<T>> Select<T>(params Expression<Func<T, bool>>[] expreesions) where T : class;

        /// <summary>
        /// 根据条件查找
        /// </summary>
        /// <typeparam name="M"></typeparam>
        /// <param name="expression">lambda表达式1</param>
        /// <param name="expression2">lambda表达式2</param>
        /// <returns></returns>
        Result<List<T>> SelectWhereIn<T, M>(Expression<Func<T, object>> expression, Expression<Func<M, object>> expression2) where M : class
         where T : class;
        #endregion

        #region ===SelectPage===
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="recordCount">返回总记录数</param>
        /// <returns></returns>
        Result<List<T>> SelectPage<T>(int pageIndex, int pageSize, out int recordCount) where T : class;

        /// <summary>
        /// 按条件进行分页查询
        /// </summary>
        /// <param name="pageIndex">第几页</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="recordCount">返回总记录数</param>
        /// <param name="expreesions">lambda表达式数组</param>
        /// <returns></returns>
        Result<List<T>> SelectPage<T>(int pageIndex, int pageSize, out int recordCount, params Expression<Func<T, bool>>[] expreesions) where T : class;
        #endregion

        #region===QuerySingle===

        /// <summary>
        /// 按条件查找单个对象
        /// </summary>
        /// <param name="expreesions">lambda表达式数组</param>
        /// <returns></returns>
        Result<T> QuerySingle<T>(params Expression<Func<T, bool>>[] expreesions) where T : class;
        #endregion

        #region ===Insert===
        /// <summary>
        /// 通过实体进行插入数据
        /// </summary>
        /// <param name="enity">实体</param>
        /// <returns></returns>
        Result<bool> Insert<T>(T enity) where T : class;
        /// <summary>
        /// 返回自增主键ID
        /// </summary>
        /// <param name="enity">实体</param>
        /// <returns>返回自增主键ID</returns>
        Result<int> PrimaryKeyInsert<T>(T enity) where T : class;

        /// <summary>
        /// 批量插入实体集
        /// </summary>
        /// <param name="enitys">实体集</param>
        /// <returns></returns>
        Result<bool> MultiInsert<T>(IEnumerable<T> enitys) where T : class;
        #endregion

        #region ===Update===
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="enity">实体</param>
        /// <returns></returns>
        Result<bool> Update<T>(T enity) where T : class;

        /// <summary>
        /// 按条件更新实体
        /// </summary>
        /// <param name="enity">动态实体</param>
        /// <param name="expreesions">lambda表达式数组</param>
        /// <returns></returns>
        Result<bool> Update<T>(dynamic enity, params Expression<Func<T, bool>>[] expreesions) where T : class;

        #endregion

        #region ===Delete===
        /// <summary>
        /// 根据实体删除数据
        /// </summary>
        /// <param name="enity">实体</param>
        /// <returns></returns>
        Result<bool> Delete<T>(T enity) where T : class;
        /// <summary>
        /// 按条件删除数据
        /// </summary>
        /// <param name="expreesions">lambda表达式数组</param>
        /// <returns></returns>
        Result<bool> Delete<T>(params Expression<Func<T, bool>>[] expreesions) where T : class;
        #endregion

        #region ======SelectSum
        Result<dynamic> SelectSum<T>(Expression<Func<T, object>> property, params Expression<Func<T, bool>>[] expressions) where T : class;
        #endregion

        #region ===Exist===
        /// <summary>
        /// 判断是否存在
        /// </summary>
        /// <param name="expression">lambda表达式数组</param>
        /// <param name="expressions">lambda表达式数组</param>
        /// <returns></returns>
        Result<bool> Esxist<T>(Expression<Func<T, object>> expression, params Expression<Func<T, bool>>[] expressions) where T : class;
        #endregion

        #region ===selectCount==
        /// <summary>
        /// 查找总记录数
        /// </summary>
        /// <param name="expression">lambda表达式数组</param>
        /// <param name="expressions">lambda表达式数组</param>
        /// <returns></returns>
        Result<int> SelectCount<T>(Expression<Func<T, object>> expression, params Expression<Func<T, bool>>[] expressions) where T : class;
        #endregion

        #region ===SelectWhereIn===
        /// <summary>
        /// SelectWhereIn
        /// </summary>
        /// <param name="porperty">某一属性</param>
        /// <param name="param">此属性的值范围</param>
        /// <returns></returns>
        Result<List<T>> SelectWhereIn<T>(Expression<Func<T, object>> porperty, IEnumerable<object> param) where T : class;

        /// <summary>
        /// SelectWhereIn
        /// </summary>
        /// <param name="porperty">某一属性</param>
        /// <param name="param">此属性的值范围</param>
        /// <param name="expressions">where条件</param>
        /// <returns></returns>
        Result<List<T>> SelectWhereIn<T>(Expression<Func<T, object>> porperty, IEnumerable<object> param, params Expression<Func<T, bool>>[] expressions) where T : class;
        #endregion
    }
}
